package cn.net.isir.core;

import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;

/**
 * @author liuxubo
 * @filename ShiroUsernamePasswordPhoneToken.java
 * @package cn.net.isir.core
 * @email lxb@isir.net.cn
 * @date 2019/01/07
 * @comment 手机号类
 * @since 1.8
 */
public class ShiroUsernamePasswordPhoneToken extends UsernamePasswordToken {

    /**
     * 手机号
     */
    private String phone = null;

    public ShiroUsernamePasswordPhoneToken() {

    }

    public ShiroUsernamePasswordPhoneToken(String phone) {
        this.phone = phone;
    }

    public ShiroUsernamePasswordPhoneToken(String username, String password) {
        super(username, password);
    }

    /**
     * Simply returns {@link #getUsername() getUsername()}.
     *
     * @return the {@link #getUsername() username}.
     * @see AuthenticationToken#getPrincipal()
     */
    @Override
    public Object getPrincipal() {
        return phone == null ? getUsername() : phone;
    }

    /**
     * Returns the {@link #getPassword() password} char array.
     *
     * @return the {@link #getPassword() password} char array.
     * @see AuthenticationToken#getCredentials()
     */
    @Override
    public Object getCredentials() {
        return phone == null ? getPassword() : "OK";
    }
}
